<template>
	<view class="top-bar">
		<view class="status-bar" :style="{height: statusBarHeight + 'px'}"></view>
		<view class="top-view" :style="{paddingRight: menuButtonWidth + 'px'}">
			<scroll-view scroll-x="true" style="height: 88rpx;">
				<view class="tab-list">
					<view class="tab" v-for="item in list" :key="item.id" @click="selectTab(item)">
						<text class="tab-text" :class="[{ 'tab-text--active': item.id === cid }]">{{ item.name }}</text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default: () => [],
			},
			cid: String,
		},
		data() {
			return {
				statusBarHeight: 0,
				menuButtonWidth: 0,
			}
		},
		created() {
			const sysinfo = uni.getSystemInfoSync()
			this.statusBarHeight = sysinfo.statusBarHeight
			
			const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
			this.menuButtonWidth = menuButtonInfo.width + 10
		},
		methods: {
			selectTab(data) {
				if (data.id === this.cid) {
					// uni.navigateBack()
					return
				}
				
				this.$emit('change', data)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.top-bar {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		background-color: rgba(#000, 0.08);
	}
	.top-view {
		padding-left: 20rpx;
	}
	.tab-list {
		flex-direction: row;
		height: 88rpx;
	}
	.tab {
		padding: 0 24rpx;
		align-items: center;
		justify-content: center;
	}
	.tab-text {
		font-size: 32rpx;
		font-weight: bold;
		color: rgba(#fff, 0.8);
		&--active {
			color: #fff;
		}
	}
</style>